package com.itqf.Util;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

/**
 * @author 李鹏鹏
 * @version 1.0
 * @ClassName: UpLoadUtil
 * @Description: TODO
 * @Date 2019/10/19 0019 上午 9:33
 * @since JDK 1.8
 */
public class UpLoadUtil {
    public static String  getup(MultipartFile headPortrait, HttpServletRequest request) {
        //转换服务器地址
    String realPath = request.getRealPath("/upload");
    //得到文件名称
    String originalFilename = headPortrait.getOriginalFilename();
    //上传
        try{

            File file = new File(realPath);
            if (!file.exists()) {
                file.mkdirs();
            }
        String uuid = UuidUtil.getUuid();
        originalFilename = uuid+originalFilename;
        headPortrait.transferTo(new File(realPath + "/" + originalFilename));
        originalFilename="http://101.200.54.176:8080/upload/"+originalFilename;
    } catch(IOException e)
    {
        e.printStackTrace();
    }

    return originalFilename;
}




}
